<?php
namespace app\api\model;
use think\Config;
use think\Db;
class DocmeeModel extends \app\common\model\CommonModel
{
    /**
     * @param string $userid
     */
    public function generate_token($userid)
    {
        try {
            $header = [
                "Content-Type: application/json",
                "Api-Key: " . Config::get('docmee_api_key'),
            ];
            $data = [
                'uid' => $userid,
            ];
            $url = Config::get('docmee_api_url') . 'api/user/createApiToken';
            $result = httpRequest($url, json_encode($data), $header);
            if (isset($result['code']) && $result['code'] == 0) {
                return $result['data'];
            }else {
                throw new \Exception($result['message']);
            }                       
        } catch (\Exception $e) {
            throw new \Exception($e->getMessage());
        }
    }   
    
}